import React from 'react';
import { Tooltip, Tag, Icon } from 'antd';
import { Brief } from '@/molecules';
import { DemandStatus, CutCornerTag } from '../components';

const CONFIRM_MAP = {
    2: '需求已分配',
    3: '负责人变更中'
};

/**
 * 展示发起人、负责人、申请时间等信息
 * @param {Boolean} showNamePopOver 是否在hover姓名时显示悬浮窗
 */
export default function DemandBrief({ data = {}, showNamePopOver = false }) {
    const {
        dutyName = '--',
        launchEmployeeName = '--',
        principalEmployeeName = '--',
        workCity = '--',
        workYearsName = '--',
        recruitDegreeName = '--',
        rankValue = '--',
        applyDate = '--',
        organizationName = '--',
        recruitStatus = 1,
        preparePrincipalEmployeeName,
        refuseStatus,
        channelReleaseStatus,
        companyName,
        allReleasedChannelDownLine
    } = data;

    // const data = {
    //     title: 'VV Work产品经理',
    //     tags: [<Tag>待认领</Tag>],
    //     descriptions: ['p5', '3~5年', '本科及以上', '厦门、深圳'],
    //     captions: [
    //         { label: '发起人', value: '李某某' },
    //         { label: '负责人', value: '--' },
    //         { label: '申请时间', value: '8-26' },
    //         { label: '需求部门', value: '产品部' }
    //     ]
    // };
    const isPublished = channelReleaseStatus === 1;

    const principal =
        refuseStatus === 0 && CONFIRM_MAP[recruitStatus] ? (
            <Tooltip title={`${CONFIRM_MAP[recruitStatus]}，待${preparePrincipalEmployeeName}接受`}>
                <span style={{ display: 'inline-block', minWidth: 30, minHeight: 10, cursor: 'pointer' }}>
                    {principalEmployeeName || '--'}
                </span>
                <Icon type="info-circle" style={{ marginLeft: 8, color: 'red' }} />
            </Tooltip>
        ) : (
            principalEmployeeName || '--'
        );

    const releaseTag = isPublished ? (
        <Tag color="green" key={2}>
            已发布
        </Tag>
    ) : (
        <Tag key={2}>未发布</Tag>
    );

    const dataSource = {
        title: dutyName,
        tags: [
            <DemandStatus status={recruitStatus} key={1} />,
            Number(recruitStatus) === 3 && !allReleasedChannelDownLine ? releaseTag : null,
            allReleasedChannelDownLine ? <CutCornerTag>已下线</CutCornerTag> : null
        ],
        descriptions: [rankValue, workYearsName, recruitDegreeName, workCity],
        originalData: data, // 传入原始数据以供Brief组件获取机构编码。
        captions: [
            {
                label: '发起人',
                value: launchEmployeeName,
                showNamePopOver,
                orgCodeKey: 'launchEmployeeOrganizationCode',
                employeeCodeKey: 'launchEmployeeCode'
            },
            {
                label: '负责人',
                value: principal,
                showNamePopOver,
                orgCodeKey: 'principalEmployeeOrganizationCode',
                employeeCodeKey: 'principalEmployeeCode'
            },
            { label: '申请时间', value: applyDate, noHover: true },
            { label: '需求部门', value: organizationName, noHover: true },
            { label: '行政机构', value: companyName, noHover: true }
        ]
    };

    return <Brief data={dataSource} />;
}
